#pragma once

struct Person
{
	uint32_t _number = 0;
	uint32_t _province = 0;
	uint32_t _city = 0;

	Person(const PersonPb& pb);
	void code(PersonPb& pb);
	void decode(const PersonPb& pb);
};

struct Province
{
	uint32_t _id = 0;
	std::string _name;

	Province(const ProvincePb& pb);
	void code(ProvincePb& pb);
	void decode(const ProvincePb& pb);
};

struct City
{
	uint32_t _id = 0;
	std::string _name;

	City(const CityPb& pb);
	void code(CityPb& pb);
	void decode(const CityPb& pb);
};

class NumberAllocation
{
	bool _run = true;
	std::list<Person> _person;
	std::list<Province> _province;
	std::list<City> _city;

	std::map<size_t, std::list<Person>::iterator> _numberPerson;

public:
	bool run();

	void code(NumberAllocationPb& pb);
	void decode(const NumberAllocationPb& pb);

	bool command(const std::vector<std::string>& cmd);
	bool commandCheck(const std::vector<std::string>& cmd);
	bool commandShow(const std::vector<std::string>& cmd);

	bool init();
	void quit();

	bool getNumber(std::list<size_t>& out, const std::string& num);
	bool getNumberN(size_t& nBeg, size_t& nEnd, char ch);
};